package com.wd.home.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wd.common.bean.LookcarBean
import com.wd.home.R
import java.text.SimpleDateFormat
import java.util.Date

/**
 * 作者：马海钊
 * 时间：2024/5/26 21:00
 * 功能：
 */
class HomeManylistAdapter(
    private var context: Context,
    private var list: LookcarBean.HomeManyListBean
) :
    RecyclerView.Adapter<HomeManylistAdapter.ViewHolder>() {



    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view =
            LayoutInflater.from(context).inflate(R.layout.item_homemany_recylist, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.name.setText(list.result.get(position).nickName)
        holder.relog.setText(list.result.get(position).title)
        holder.time.text="${SimpleDateFormat("yyyy-MM-dd").format(Date(list.result[position].releaseTime))+"发布"}"
        Glide.with(context)
            .load(list.result.get(position).mediaUrl)
            .into(holder.price)
    }

    override fun getItemCount(): Int {
        return list.result.size
    }

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val name: TextView = view.findViewById(R.id.item_homemany_recylist_name)
        val price: ImageView = view.findViewById(R.id.item_homemany_recylist_price)
        val relog: TextView = view.findViewById(R.id.item_homemany_recylist_log)
        val time: TextView = view.findViewById(R.id.item_homemany_recylist_time)
    }
}